*** This code adjusts the TAXSIM output to account for the saver's credit

*NOTE: mstat :: 1=single/hoh, 2=mfj, 6=mfs, 8=dependent taxpayer

*NOTE: v10 = agi

gen     TEMP_mstat = mstat
replace TEMP_mstat = 4 if mstat==1 & depx>0

gen double TEMP_thresh1 = 38500*(TEMP_mstat==2) + 28875*(TEMP_mstat==4) + 19250*(!inlist(TEMP_mstat,2,4))
gen double TEMP_thresh2 = TEMP_thresh1 + 1500 + 1500*(TEMP_mstat==2)
gen double TEMP_thresh3 = 64000*(TEMP_mstat==2) + 48000*(TEMP_mstat==4) + 32000*(!inlist(TEMP_mstat,2,4))

gen     TEMP_frac = 0
replace TEMP_frac = 0.1 if v10<=TEMP_thresh3
replace TEMP_frac = 0.2 if v10<=TEMP_thresh2
replace TEMP_frac = 0.5 if v10<=TEMP_thresh1

gen double TEMP_sav_cred = max(0,min(TEMP_frac*cdw_sav_cred_base,v28-500*(depx-dep17)))

replace fiitax = fiitax - TEMP_sav_cred

drop TEMP*
